const path = require('path');
const html =require('html-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const webpack = require('webpack');
const myplugin = require('../myplugin.js')
module.exports={
    entry:'./src/index.js', 
    output:{
        filename: 'index.[hash:4].js',
        path:path.resolve(__dirname,'../dist')
    },
    resolveLoader:{
        modules: ['node_modules','./'],
    },
    module:{
        //告诉webpack不用解析jquery,loadsh中的依赖
        noParse:/jquery|loadsh/,
        rules:[
            {
                test:/\.js$/,
                //tread-loader多线程打包
                use:['thread-loader','myloader',{
                    loader:'babel-loader',
                    options:{
                        presets:[
                            '@babel/preset-env'
                        ]
                    }
                }],
                exclude:/node_modules/,
            }
        ]
    },
    plugins:[
        new myplugin(),
        //打包编译时，先去manifest中查找，如果没有再打包，有的话就不用打包
        new webpack.DllReferencePlugin({
            manifest:path.resolve(__dirname,'../dist','manifest.json')
        }),
        new CleanWebpackPlugin({
            //告诉插件，这些文件该清还是不该清
            cleanOnceBeforeBuildPatterns:['**/*','!dll_*','!mani*']
        }),
        new html({
            template:'./public/index.html',
            filename:"index.html"
        }),
        //这个插件是默认全局导入，不用每个文件都import哪些类库
        new webpack.ProvidePlugin({
            '$':'jquery',//前面这个键值我们可以自己定义
            'React':'react',
            '_':'loadsh'
        }),
        //忽略
        new webpack.IgnorePlugin(/^\.\/locale$/,/moment$/)
    ]
}